package com.cuit.lotery.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.cuit.lotery.entity.Setting;
import com.cuit.lotery.mapper.SettingMapper;
import com.cuit.lotery.service.SettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SettingServiceImpl implements SettingService {
    @Autowired
    SettingMapper mapper;
    @Override
    public Setting getOne(String key) {
        return mapper.selectOne(new QueryWrapper<Setting>()
                .eq("skey", key));
    }

    @Override
    public boolean add(Setting setting) {
        return mapper.insert(setting) == 1;
    }

    @Override
    public boolean update(Setting setting) {
        return mapper.update(setting, new UpdateWrapper<Setting>()
                .eq("skey", setting.getSkey())) == 1;
    }

    @Override
    public List<Setting> getAll() {
        return mapper.selectList(null);
    }
}
